﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LP580.CG
{
    /// <summary>
    /// clsTradeInfo 的摘要说明
    /// </summary>
    public class clsTradeInfo
    {
        #region 构造函数

        public clsTradeInfo() { }

        public clsTradeInfo(int prmTradeInfoID)
        {
            clsTradeInfo entity = clsTradeInfo.GetByKey(prmTradeInfoID);
            this._tradeinfoid = entity._tradeinfoid;
            this._userid = entity._userid;
            this._tradeinfotitle = entity._tradeinfotitle;
            this._tradeinfodetials = entity._tradeinfodetials;
            this._tradeinfosupport = entity._tradeinfosupport;
            this._tradeinforequest = entity._tradeinforequest;
            this._tradeinfodatetime = entity._tradeinfodatetime;
            this._tradeinfohits = entity._tradeinfohits;
        }

        #endregion

        public static clsTradeInfo GetByKey(int prmTradeInfoID)
        {
            clsTradeInfo entity = new clsTradeInfo();
            DBase dbo = new DBase();
            System.Data.IDataReader dr = dbo.ExecuteReader("SELECT * FROM [tbl_TradeInfo] WHERE TradeInfoID=" + prmTradeInfoID.ToString());
            if (dr.Read())
            {
                entity._tradeinfoid = (int)dr["TradeInfoID"];
                entity._userid = (int)dr["UserID"];
                entity._tradeinfotitle = (string)dr["TradeInfoTitle"];
                entity._tradeinfodetials = (string)dr["TradeInfoDetials"];
                entity._tradeinfosupport = (string)dr["TradeInfoSupport"];
                entity._tradeinforequest = (string)dr["TradeInfoRequest"];
                entity._tradeinfodatetime = (DateTime)dr["TradeInfoDateTime"];
                entity._tradeinfohits = (int)dr["TradeInfoHits"];
            }
            dr.Dispose();
            dr = null;
            dbo.CloseConn();
            dbo = null;
            return entity;
        }

        #region 增删改数据库操作

        public static int Insert(clsTradeInfo prmEntity)
        {
            DataTableManage SaveDTM = new DataTableManage();
            string sql;
            sql = string.Format("insert into [tbl_TradeInfo](" +
                            " [UserID]," +
                            " [TradeInfoTitle]," +
                            " [TradeInfoDetials]," +
                            " [TradeInfoSupport]," +
                            " [TradeInfoRequest]," +
                            " [TradeInfoDateTime]," +
                            " [TradeInfoHits]" +
            ") values (" +
                    "@UserID," +
                    "@TradeInfoTitle," +
                    "@TradeInfoDetials," +
                    "@TradeInfoSupport," +
                    "@TradeInfoRequest," +
                    "@TradeInfoDateTime," +
                    "@TradeInfoHits" +
            ")");
            SaveDTM.Sql = sql;
            SaveDTM.AddNewParam("@UserID", prmEntity._userid);
            SaveDTM.AddNewParam("@TradeInfoTitle", prmEntity._tradeinfotitle);
            SaveDTM.AddNewParam("@TradeInfoDetials", prmEntity._tradeinfodetials);
            SaveDTM.AddNewParam("@TradeInfoSupport", prmEntity._tradeinfosupport);
            SaveDTM.AddNewParam("@TradeInfoRequest", prmEntity._tradeinforequest);
            SaveDTM.AddNewParam("@TradeInfoDateTime", prmEntity._tradeinfodatetime);
            SaveDTM.AddNewParam("@TradeInfoHits", prmEntity._tradeinfohits);
            SaveDTM.Insert();
            return 1;
        }

        public static bool Delete(int prmTradeInfoID)
        {
            DBase dbo = new DBase();
            dbo.ExecSql("DELETE FROM [tbl_TradeInfo] WHERE TradeInfoID=" + prmTradeInfoID.ToString());
            dbo.CloseConn();
            dbo = null;
            return true;
        }

        public static bool Update(clsTradeInfo prmEntity)
        {
            DataTableManage SaveDTM = new DataTableManage();
            string sql;
            sql = "UPDATE [tbl_TradeInfo] SET " +
                "[UserID] = @UserID, " +
                "[TradeInfoTitle] = @TradeInfoTitle, " +
                "[TradeInfoDetials] = @TradeInfoDetials, " +
                "[TradeInfoSupport] = @TradeInfoSupport, " +
                "[TradeInfoRequest] = @TradeInfoRequest, " +
                "[TradeInfoDateTime] = @TradeInfoDateTime, " +
                "[TradeInfoHits] = @TradeInfoHits " +
            " WHERE TradeInfoID=@TradeInfoID";
            SaveDTM.Sql = sql;
            SaveDTM.AddNewParam("@UserID", prmEntity._userid);
            SaveDTM.AddNewParam("@TradeInfoTitle", prmEntity._tradeinfotitle);
            SaveDTM.AddNewParam("@TradeInfoDetials", prmEntity._tradeinfodetials);
            SaveDTM.AddNewParam("@TradeInfoSupport", prmEntity._tradeinfosupport);
            SaveDTM.AddNewParam("@TradeInfoRequest", prmEntity._tradeinforequest);
            SaveDTM.AddNewParam("@TradeInfoDateTime", prmEntity._tradeinfodatetime);
            SaveDTM.AddNewParam("@TradeInfoHits", prmEntity._tradeinfohits);
            SaveDTM.AddNewParam("@TradeInfoID", prmEntity._tradeinfoid);
            SaveDTM.Update();
            return true;
        }

        #endregion

        public static List<clsTradeInfo> GetCollection()
        {
            List<clsTradeInfo> ls = new List<clsTradeInfo>();
            DBase dbo = new DBase();
            string sql = "SELECT TradeInfoID FROM [tbl_TradeInfo] ORDER BY TradeInfoID DESC";
            System.Data.IDataReader dr = dbo.ExecuteReader(sql);
            while (dr.Read())
            {
                ls.Add(clsTradeInfo.GetByKey((int)dr[0]));
            }
            dr.Dispose();
            dr = null;
            dbo.CloseConn();
            dbo = null;
            return ls;
        }

        #region 字段属性

        private int _tradeinfoid = 0;
        /// <summary>
        /// 招商信息ID-自增
        /// </summary>
        public int TradeInfoID
        {
            get { return _tradeinfoid; }
            set { _tradeinfoid = value; }
        }

        private int _userid = 0;
        /// <summary>
        /// 所属用户ID
        /// </summary>
        public int UserID
        {
            get { return _userid; }
            set { _userid = value; }
        }

        private string _tradeinfotitle = "";
        /// <summary>
        /// 信息标题
        /// </summary>
        public string TradeInfoTitle
        {
            get { return _tradeinfotitle; }
            set { _tradeinfotitle = value; }
        }

        private string _tradeinfodetials = "";
        /// <summary>
        /// 详细说明
        /// </summary>
        public string TradeInfoDetials
        {
            get { return _tradeinfodetials; }
            set { _tradeinfodetials = value; }
        }

        private string _tradeinfosupport = "";
        /// <summary>
        /// 招商支持
        /// </summary>
        public string TradeInfoSupport
        {
            get { return _tradeinfosupport; }
            set { _tradeinfosupport = value; }
        }

        private string _tradeinforequest = "";
        /// <summary>
        /// 招商要求
        /// </summary>
        public string TradeInfoRequest
        {
            get { return _tradeinforequest; }
            set { _tradeinforequest = value; }
        }

        private DateTime _tradeinfodatetime = new DateTime(1900, 1, 1);
        /// <summary>
        /// 信息添加时间
        /// </summary>
        public DateTime TradeInfoDateTime
        {
            get { return _tradeinfodatetime; }
            set { _tradeinfodatetime = value; }
        }

        private int _tradeinfohits = 0;
        /// <summary>
        /// 信息被点击数
        /// </summary>
        public int TradeInfoHits
        {
            get { return _tradeinfohits; }
            set { _tradeinfohits = value; }
        }

        #endregion
    }
}
